package com.bx.implatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bx.implatform.entity.CallRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: yufeng
 * @date: 2024-02-20
 * @description:
 */
public interface CallRecordMapper extends BaseMapper<CallRecord> {
    /**
     * 查询当前用户的通话记录
     * @param userId 当前用户Id
     * @param callStatus 接听状态
     * @return 通话记录
     */
    @Select("<script> select id, send_id as sendId, receive_id as receiveId, call_status as callStatus, call_mins as callMins, created_time as createdTime" +
            " from im_call_record where (send_id = #{userId} or receive_id = #{userId})"
            + "<if test='callStatus != null and callStatus !=\"\"'> and call_status = #{callStatus} </if> order by created_time desc "
            + "</script>")
    List<CallRecord> selectCallRecords(@Param("userId") Long userId, @Param("callStatus") String callStatus);

    /**
     * 查询与某人的通话记录
     * @param currentUserId 当前用户Id
     * @param peerUserId 对方用户Id
     * @return 通话记录
     */
    @Select("select id, send_id as sendId, receive_id as receiveId, call_status as callStatus, call_mins as callMins, created_time as createdTime from im_call_record " +
            "where (send_id = #{currentUserId} and receive_id = #{peerUserId}) " +
            "or (send_id = #{peerUserId} and receive_id = #{currentUserId}) " +
            "and created_time >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) " +
            "and created_time <= CURDATE() order by created_time desc ")
    List<CallRecord> selectPersonalCallRecords(@Param("currentUserId") Long currentUserId, @Param("peerUserId") Long peerUserId);
}
